var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        userId : $("#id").val(),
        xiangmuId:$("#xiangmuId").val(),
        xiangmu : {},
        votelist:[],
        show : false,
        total:0,
        tongyishu:0,
        butongyishu:0,

        issubmited:false,
        isallsubmited:false,

        pageIndex : 1,
        pageSize :15,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",
    },
    created : function() {
        var _this = this;

        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        _this.findIsacticed();


    },
    methods : {

        toRefresh:function (){

            location.reload();
        },

        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.xiangmuleixing=_this.xiangmu.xiangmuleixing;
                        _this.checkIsSubmited();
                        _this.checkIsAllSubmited();
                        _this.getchuangxinchanpinResultCount();

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.issubmited=true;
                        }
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsAllSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsAllSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.isallsubmited=true;
                        }

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/chuangxinchanpin/findbiaojuelist",{
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead > <tr>\n" +
                            "       <th rowspan='2' style=\"text-align:center;vertical-align:middle;width:50px;\" >序号</th>\n" +
                            "       <th rowspan='2' style=\"text-align:center;vertical-align:middle;width:120px;\">药品名称</th>\n" +
                            "       <th rowspan='2' style=\"text-align:center;vertical-align:middle;width:100px;\" >规格</th>\n" +
                            "       <th rowspan='2' style=\"text-align:center;vertical-align:middle;width:100px;\" >单位</th>\n" +
                            "       <th rowspan='2' style=\"text-align:center;vertical-align:middle;width:100px;\" >价格（元）</th>\n" +
                            "       <th rowspan='2' style=\"text-align:center;vertical-align:middle;\" >生产厂家</th>\n" +
                            "       <th rowspan='2' style=\"text-align:center;vertical-align:middle;width:180px;\" >执行时间</th>\n" +
                            "       <th colspan='2' style=\"text-align:center;vertical-align:middle;width:160px;\" >完成金额（万元）</th>\n" +
                            "       <th rowspan='2' style=\"text-align:center;vertical-align:middle;width:100px;\" >表决意见（同意保留请打勾）</th>\n" +
                            "   </tr>" +
                            "<tr>" +
                            " <th  style=\"text-align:center;vertical-align:middle;width:80px;\" >院本部</th>\n" +
                            " <th  style=\"text-align:center;vertical-align:middle;width:80px;\" >秦淮</th>\n" +
                            "</tr>" +
                            "    </thead></table></div><div class='table-body'><table><tbody>";
                        if(data.Biaojuelist.length>0){
                            _this.show = true;
                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.Biaojuelist.length; i++) {
                                var mmChuangxinOne = data.Biaojuelist[i];
                                var mmResult=mmChuangxinOne.result;
                                var mmId=mmChuangxinOne.id;

                                var mmpaixuhao = mmChuangxinOne.ordernumber;
                                var mmyaowumingcheng = mmChuangxinOne.yaopinmingcheng;
                                var mmguige = mmChuangxinOne.guige;
                                var mmdanwei = mmChuangxinOne.danwei;
                                var mmjiage = mmChuangxinOne.jiage;
                                var mmshengchanchangjia = mmChuangxinOne.shengchanchangjia;
                                var mmzhixingshijian = mmChuangxinOne.zhixingshijian;
                                var mmyuanbenbu = mmChuangxinOne.yuanbenbu;
                                var mmqinhuai = mmChuangxinOne.qinhuai;

                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px;'>" + mmpaixuhao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:120px;'>" + mmyaowumingcheng + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmguige + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmdanwei + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmjiage + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:'>" + mmshengchanchangjia + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:180px;'>" + mmzhixingshijian + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:80px;'>" + mmyuanbenbu + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:80px;'>" + mmqinhuai + "</td>";


                                var mmBtndiv="";
                                if(_this.issubmited){
                                    if(mmResult==null||mmResult==0){
                                        mmBtndiv="<div style=\"text-align:center;\"><input disabled onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                    if(mmResult==1){
                                        mmBtndiv="<div style=\"text-align:center;\"><input disabled checked onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                }
                                if(!_this.issubmited) {
                                    if(mmResult==null||mmResult==0){
                                        mmBtndiv="<div style=\"text-align:center;\"><input  onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                    if(mmResult==1){
                                        mmBtndiv="<div style=\"text-align:center;\"><input checked  onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                }
                                mmHtml +="<td style='text-align:center;vertical-align:middle;width:100px;height: 100%'>" + mmBtndiv + "</td>";

                                mmHtml += "</tr>";

                            }
                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        getchuangxinchanpinResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/chuangxinchanpinjieguo/getChuangxinchanpinResultCount', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.tongyishu=data.tongyiShu;
                        _this.butongyishu=data.butongyiShu;
                        _this.total=data.total;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        tosubmit:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/chuangxinchanpinjieguo/submit', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        _this.issubmited=true;
                        layer.alert("提交成功");
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        /**
         * 合并单元格(如果结束行传0代表合并所有行)
         * @param table1    表格的ID
         * @param startRow  起始行
         * @param endRow    结束行
         * @param col   合并的列号，对第几列进行合并(从0开始)。第一行从0开始
         */
        /* mergeCell: function (tableId, startRow, endRow, col) {
             alert(startRow)
             var tb = document.getElementById(tableId);
             if (col >= tb.rows[0].cells.length) {
                 return;
             }
             if (col == 0) { endRow = tb.rows.length-1; }
             for (var i = startRow; i < endRow; i++) {
                 if (tb.rows[startRow].cells[col].innerHTML == tb.rows[i + 1].cells[0].innerHTML) {
                     tb.rows[i + 1].removeChild(tb.rows[i + 1].cells[0]);
                     tb.rows[startRow].cells[col].rowSpan = (tb.rows[startRow].cells[col].rowSpan | 0) + 1;
                     if (i == endRow - 1 && startRow != endRow) {
                         mc(tableId, startRow, endRow, col + 1);
                     }
                 } else {
                     this.mergeCell(tableId, startRow, i + 0, col + 1);
                     startRow = i + 1;
                 }
             }
          },*/

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },
    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.findBiaojuelist();
        }
    }
})